package com.alan.base.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.alan.base.utils.Logger;

import java.util.ArrayList;
import java.util.List;

public class BaseActivity extends AppCompatActivity {

    protected List<Activity> activityList = new ArrayList<>();
    protected String TAG = getClass().getSimpleName();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activityList.add(this);
        Logger.v(TAG+" onCreate");
    }

    @Override
    protected void onStart() {
        super.onStart();
        Logger.v(TAG+" onStart");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Logger.v(TAG+" onResume");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Logger.v(TAG+" onPause");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Logger.v(TAG+" onStop");
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Logger.v(TAG+" onNewIntent");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Logger.v(TAG+" onRestart");
    }

    @Override
    protected void onDestroy() {
        activityList.remove(this);
        super.onDestroy();
        Logger.v(TAG+" onDestroy");
    }

    /**
     * 退出该应用的所有activity
     */
    public void clearActivity() {
        for (Activity activity : activityList) {
            activity.finish();
        }
    }
}
